package servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.remote.ArticuloRemoto;
import dominio.Articulo;

public class AumentarStockServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1039312487055628453L;

	@EJB(beanName = "articuloBean")
	private ArticuloRemoto articuloRemoto;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String stock = req.getParameter("stock");
		String[] parameterValues = req.getParameterValues("seleccionado");
		for (int i = 0; i < parameterValues.length; i++) {
			String id = parameterValues[i];
			Articulo articulo = articuloRemoto.findByCodigo(Long.valueOf(id));
			articuloRemoto.aumentarStock(articulo, Integer.valueOf(stock));
		}
	}
}
